/*
 * -------------------------------------------------------------------------
 * DSPEncoder.h -- Encoder definitions for the DSP
 * Speech Watermarkin
 * Copyright (C) 2011-2012  Oriol Parera Fiestas
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * -------------------------------------------------------------------------
 */

#ifndef dspencoder_h
#define dspencoder_h

#include <std.h>
#include <log.h>
#include <pip.h>
#include <swi.h>
#include <sys.h>
#include <sem.h>
#include <hst.h>
#include <lio.h>
#include "plio.h"
#include <stdlib.h>
#include <rtdx.h>     
#include <tsk.h>
                  /* RTDX                     */
//#include "target.h"                     /* TARGET_INITIALIZE()      */
#include <dsk5416_dma_pcm3002.h>

#include "parameters.h"

//#define SEND_DATA_TO_HOST 1

/* Set CONTROLLER_FXN_TABLE in the linker command file. */
extern LIO_Fxns CONTROLLER_FXN_TABLE;
static LIO_Fxns *controller = &CONTROLLER_FXN_TABLE;

/* this is the default configuration object. it can be changed but it is configured to sample
   at 8KHZ - 16 bit by default.
   This is exactly my need
*/
extern DSK5416_DMA_PCM3002_Setup DSK5416_DMA_PCM3002_SETUP; 

extern far LOG_Obj trace; /* application printf() log, any size */ 
extern far PIP_Obj pipRx; /* writerNotify -> PLIO_rxPrime(plioRx)
                           * readerNotify -> SWI_andn(swiEcho,1) */
extern far PIP_Obj pipTx; /* writerNotify -> SWI_andn(swiEcho,2)
                           * readerNotify -> PLIO_txPrime(plioTx) */
extern far SWI_Obj swiRead;

extern far SEM_Obj semSYN;
extern far SEM_Obj semWavelet;
extern far SEM_Obj semSendToHost;

RTDX_CreateOutputChannel(ochan);

/*
 *  'plioRx' and 'plioTx' objects will be initialized by PLIO_new(). 
 */
PLIO_Obj plioRx, plioTx;


//The number of buffers used for buffering is.... the rest of buffers are ignored
#define MAX_BUFFERS 4

short buffer0[MARK_SAMPLES];
short buffer1[MARK_SAMPLES];
short buffer2[MARK_SAMPLES];
short buffer3[MARK_SAMPLES];/* 1kb */
short buffer4[MARK_SAMPLES]; 
short buffer5[MARK_SAMPLES];
short buffer6[MARK_SAMPLES];
short buffer7[MARK_SAMPLES];/*2kb*/
short buffer8[MARK_SAMPLES];
short buffer9[MARK_SAMPLES];
short buffer10[MARK_SAMPLES];
short buffer11[MARK_SAMPLES]; /*3kb*/
short buffer12[MARK_SAMPLES]; 
short buffer13[MARK_SAMPLES];
short buffer14[MARK_SAMPLES];
short buffer15[MARK_SAMPLES];/*4kb*/
short buffer16[MARK_SAMPLES];
short buffer17[MARK_SAMPLES];
short buffer18[MARK_SAMPLES];
short buffer19[MARK_SAMPLES]; /*5kb*/
short buffer20[MARK_SAMPLES]; 
short buffer21[MARK_SAMPLES];
short buffer22[MARK_SAMPLES];
short buffer23[MARK_SAMPLES];/*6kb*/
short buffer24[MARK_SAMPLES];
short buffer25[MARK_SAMPLES];
short buffer26[MARK_SAMPLES];
short buffer27[MARK_SAMPLES]; /*7kb*/


unsigned int status;
//short *readingBuffer;
//short *writingBuffer;
short *waveletBuffer;

void inits();
short *getBuffer(unsigned int n);

#endif /* #ifndef dspencoder_h */
